package com.jason.cloud.engine.share.driver.pack.service;

import com.jason.cloud.engine.share.driver.pack.bean.PackBean;
import com.jason.cloud.engine.share.driver.pack.dao.PackDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class PackServiceImpl implements PackService {

    private static final Logger logger = LoggerFactory.getLogger(PackServiceImpl.class);

    @Resource
    private PackDao packDao;

    /**
     * 根据ID查询对象
     * @param id
     * @return
     */
    public PackBean queryPackById(String id) {
        PackBean packBean = null;
        try {
            packBean = this.packDao.queryPackById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return packBean;
    }

    /**
     * 保存
     * @param pack
     * @return
     */
    public void insertPack(PackBean pack) {
        try {
            this.packDao.insertPack(pack);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 查询否为默认的套餐
     * @return
     */
    public PackBean queryDefaultPackByIsDefault() {
        PackBean packBean = null;
        try {
            packBean = this.packDao.queryDefaultPackByIsDefault();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return packBean;
    }

    /**
     * 列举出所有的资费
     * @return
     */
    public List<PackBean> getPackByLimit(int start, int stop) {
        List<PackBean> packBean = new ArrayList<PackBean>();
        try {
            packBean = this.packDao.getPackByLimit(start, stop);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return packBean;
    }

    /**
     * 计数资费
     * @return
     */
    public int getPackCount() {
        int count = 0;
        try {
            count = this.packDao.getPackCount();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }



    /**
     * 设置资费状态为废弃
     * @param id
     */
    public void updatePackStatusDisabledById(String id) {
        try {
            this.packDao.updatePackStatusDisabledById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 设置资费状态为可用
     * @param id
     */
    public void updatePackStatusEnabledById(String id) {
        try {
            this.packDao.updatePackStatusEnabledById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 设置资费为注册默认
     * @param id
     */
    public void updatePackIsDefaultById(String id) {
        try {
            this.packDao.updatePackIsDefaultById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 设置资费为注册非默认
     * @param id
     */
    public void updatePackNotDefaultById(String id) {
        try {
            this.packDao.updatePackNotDefaultById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 加载资费
     * @return
     */
    public List<PackBean> getPackByEnabled() {
        List<PackBean> packBean = new ArrayList<PackBean>();
        try {
            packBean = this.packDao.getPackByEnabled();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return packBean;
    }
}
